package com.ks.common;

import com.ks.exception.NullValueException;

import java.math.BigDecimal;

public class Comparator {


    public static boolean compare(String symbol, BigDecimal a, BigDecimal b) {
        if (a == null || b == null) {
            throw new NullValueException("计算比较时，参数为null");
        }

        switch (symbol) {
            case "==":
                return a.compareTo(b) == 0;
            case "!=":
                return a.compareTo(b) != 0;
            case ">":
                return a.compareTo(b) > 0;
            case "<":
                return a.compareTo(b) < 0;
            case ">=":
                return a.compareTo(b) >= 0;
            case "<=":
                return a.compareTo(b) <= 0;
            default:
                return false;
        }
    }
}




